<?php
session_start();
include 'rfq_check.php';
include 'common/check.php';

$_SESSION['rfq_id']                 = "-1";
$_SESSION['rfq_categoryID']         = $_POST['hd_categoryID'];
$_SESSION['rfq_category']           = $_POST['hd_category'];
$_SESSION['rfq_marketID']           = $_POST['sl_market'];
$_SESSION['rfq_process']            = $_POST['sl_process'];
$_SESSION['rfq_requireDC']          = $_POST['rd_requireDC'];
$_SESSION['rfq_quantity']           = $_POST['txt_quantity1'] . "~" . $_POST['txt_quantity2'] . "~" . $_POST['txt_quantity3'];
$_SESSION['rfq_measure']            = $_POST['sl_measure'];
$_SESSION['rfq_annualUsage']        = $_POST['txt_annualUsage'];
$_SESSION['rfq_neededDate']         = strtotime($_POST['txt_neededDate']);
$_SESSION['rfq_awardDate']          = strtotime($_POST['txt_awardDate']);
$_SESSION['rfq_deliveryDate']       = strtotime($_POST['txt_deliveryDate']);
$_SESSION['rfq_paymentTerm']        = $_POST['sl_paymentTerms'];
$_SESSION['rfq_paymentMethod']      = $_POST['ck_paymentMethod'];
$_SESSION['rfq_referencePrice']     = $_POST['sl_referencePrice'];
$_SESSION['rfq_targetPrice']        = $_POST['txt_targetPrice'];
$_SESSION['rfq_showPrice']          = isset($_POST['ck_showPrice']) ? true: false;

if ($_POST['hd_address'] == -1) {
    include '../business/address_manager.php';
    include_once '../entity/address_entity.php';

    $addressMng = new AddressMng();
    $addressEntity = new AddressEntity();

    $addressEntity->id = "-1";
    $addressEntity->name = $addressEntity->url = $_POST['txt_folder'];
    $addressEntity->userID = $_SESSION['userID'];

    $_SESSION['rfq_folder'] = $addressMng->update($addressEntity);
    
} else {
    $_SESSION['rfq_folder'] = $_POST['sl_folder'];
}

$_SESSION['rfq_shippingCost'] = $_POST['rd_shippingCost'];

if ($_POST['hd_addressID'] != "-1") {
    $_SESSION['rfq_addressID'] = $_POST['hd_addressID'];
} else {
    include '../entity/address_entity.php';
    include '../business/address_manager.php';
    $addressEntity = new AddressEntity();
    $addressMng = new AddressMng();

    $addressEntity->addressID   = $_POST['hd_addressID'];
    $addressEntity->name        = $_POST['txt_name'];
    $addressEntity->address     = $_POST['txt_address1'];
    $addressEntity->address2    = $_POST['txt_address2'];
    $addressEntity->address3    = $_POST['txt_address3'];
    $addressEntity->city        = $_POST['txt_city'];
    $addressEntity->country     = $_POST['txt_country'];
    $addressEntity->province    = $_POST['txt_province'];
    $addressEntity->zipCode     = $_POST['txt_zipCode'];
    $addreeEntity->inTime       = time();
    $addressEntity->inUser      = $_SESSION['userID'];

    $_SESSION['rfq_addressID'] = $addressMng->update($addressEntity);
}

$_SESSION['rfq_instructions']   = $_POST['txt_instructions'];
$_SESSION['rfq_rfqIntent']      = $_POST['sl_rfqIntent'];
$_SESSION['rfq_usageDetails']   = $_POST['sl_usageDetails'];
$_SESSION['rfq_industry']       = $_POST['sl_industry'];
$_SESSION['rfq_requiredNDA']    = $_POST['hd_requiredNDA'] == "1" ? true : false;

switch (strtolower($_SESSION['rfq_category'])) {
    case "polymer":
        echo "<script>window.location.href='material.php'</script>";
        break;
    case "pigment":
        echo "<script>window.location.href='material.php'</script>";
        break;
    case "dyes":
        echo "<script>window.location.href='material.php'</script>";
        break;
    case "addtive":
        echo "<script>window.location.href='material.php'</script>";
        break;
    case "pearlescent":
        echo "<script>window.location.href='material.php'</script>";
        break;
    case "masterbatch or compound creation":
        echo "<script>window.location.href='masterbatch_compound.php'</script>";
        break;
    case "color masterbatch":
        echo "<script>window.location.href='masterbatch_compound.php'</script>";
        break;
    case "black masterbatch":
        echo "<script>window.location.href='black.php'</script>";
        break;
    case "white masterbatch":
        echo "<script>window.location.href='white.php'</script>";
        break;
    case "additives tickboxes":
        echo "<script>window.location.href='masterbatch_compound.php'</script>";
        break;
    case "custom colourmatching request":
        echo "<script>window.location.href='plastic.php'</script>";
        break;
    case "plastics processor - make something for you":
        echo "<script>window.location.href='rfq_made.php'</script>";
        break;
    case "finished products search":
        echo "<script>window.location.href='rfq_product.php'</script>";
        break;
    case "tool making":
        echo "<script>window.location.href='toolmaking.php'</script>";
        break;
    case "film drawbench machine":
        echo "<script>window.location.href='rfq_plastic.php'</script>";
        break;
    case "waste plastic recycle machine":
        echo "<script>window.location.href='rfq_plastic.php'</script>";
        break;
    default:
        echo "<script>window.location.href='material.php'</script>";
        break;
}
?>
